package demo.xlj.yuyi.studentapp;

import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.ProgressBar;

import butterknife.BindView;
import butterknife.ButterKnife;
import demo.xlj.yuyi.studentapp.base.BaseActivity;
import demo.xlj.yuyi.studentapp.dudaoyuan.DuDaoActivity;
import demo.xlj.yuyi.studentapp.login.StudentMeetLoginActivity;
import demo.xlj.yuyi.studentapp.qitabumen.QiTaActivity;
import demo.xlj.yuyi.studentapp.shetuan.SheTActivity;
import demo.xlj.yuyi.studentapp.utils.ActivityUtil;
import demo.xlj.yuyi.studentapp.utils.SharePerferencesUtils;
import demo.xlj.yuyi.studentapp.utils.ToastUtil;


/**
 * 检查sp文件-判断登录与否-判断身份
 */

public class MainActivity extends BaseActivity {

    @BindView(R.id.progressBar_Main_Activity_Loading)
    ProgressBar mProgressBarMainActivityLoading;


    private Context mContext;

    private Handler myHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (msg.what == 0) {
                judgmentLogin();
            }
        }
    };


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        mContext = MainActivity.this;
        mProgressBarMainActivityLoading.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SharePerferencesUtils.put(MainActivity.this, "isWho", "99", 0);
            }
        });
        myHandler.sendEmptyMessageDelayed(0, 2000);

    }


    /**
     * 判断是否登录
     */
    public void judgmentLogin() {
        String isWho = (String) SharePerferencesUtils.get(mContext, "isWho", "99", 0);

        if (isWho.equals("99")) {
            //表示用户未登录
            ActivityUtil.openActivityFromLeftToRight(MainActivity.this, StudentMeetLoginActivity.class);
            MainActivity.this.finish();
        } else {
            //表示用户已经登录
            if (isWho.equals("0")) {
                //表示是督导员
                ActivityUtil.openActivityFromBottomToTop(MainActivity.this, DuDaoActivity.class);
                MainActivity.this.finish();
            } else if (isWho.equals("1")) {
                //表示是社团审查部
                ActivityUtil.openActivityFromBottomToTop(MainActivity.this, SheTActivity.class);
                MainActivity.this.finish();
            } else if (isWho.equals("2")) {
                //表示是其他部门
                ActivityUtil.openActivityFromBottomToTop(MainActivity.this, QiTaActivity.class);
                MainActivity.this.finish();
            } else if (isWho.equals("3")) {
                //表示是其他社团
                ActivityUtil.openActivityFromBottomToTop(MainActivity.this, SheTActivity.class);
                MainActivity.this.finish();
            } else {
                ToastUtil.error(mContext, "系统检验用户信息失败，请重新登录", true, true);
            }
        }

    }

    /**
     * 身份判断
     */
    public void judgmentWho() {

    }


    /**
     * 跳转Activity
     *
     */
}
